package transport

import (
	"context"
	"encoding/json"
	"fmt"
	"gowork/memberGoKit/client/endpoint"
	"net/http"
)

func MemberInsertRequest(ctx context.Context, req *http.Request, r interface{}) error{
	insertRequest := r.(endpoint.MemberRequestOrResponse)
	req.URL.Path += "/insert?"+"memberList="+insertRequest.MemberList
	fmt.Println("服务端请求地址:", req.URL.Path)
	return nil
}

func MemberQueryRequest(ctx context.Context, req *http.Request, r interface{}) error{
	req.URL.Path += "/query"
	return nil

}

func MemberMapResponse(ctx context.Context, res *http.Response)(response interface{}, err error){
	var mapResponse endpoint.MemberMapResponse
	fmt.Println(res.Body)
	err = json.NewDecoder(res.Body).Decode(&mapResponse)
	if err != nil{
		fmt.Println(err)
		return nil, err
	}
	fmt.Println("返回值", mapResponse)
	return mapResponse, nil
}

func MemberQueryResponse(ctx context.Context, res *http.Response)(response interface{}, err error){
	var queryResponse endpoint.MemberRequestOrResponse
	err = json.NewDecoder(res.Body).Decode(&queryResponse)
	if err != nil{
		return nil, err
	}

	return queryResponse, nil
}